package com.qf.zyh.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.zyh.common.ResponseResult;
import com.qf.zyh.common.ResultType;
import com.qf.zyh.dao.ApiMappingMapper;
import com.qf.zyh.entity.ApiMapping;
import com.qf.zyh.services.ApiMappingServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApiMappingServicesImpl implements ApiMappingServices {
    @Autowired
    private ApiMappingMapper apiMappingMapper;

    @Override
    public ResultType table(Integer page, Integer limit, String gatewayApiName, Integer state) {
        PageHelper.startPage(page,limit);
        List<ApiMapping> list =apiMappingMapper.selectByName(gatewayApiName,state);
        list.stream().forEach(System.out::println);
        PageInfo pageInfo = new PageInfo(list);
        return new ResultType(0,"",(int)pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public ResponseResult delMa(Integer[] ids) {
        apiMappingMapper.delMa(ids);
        return ResponseResult.getSuccess();
    }

    @Override
    public ResponseResult addMa(ApiMapping a) {
        int i = apiMappingMapper.insertSelective(a);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("新增失败");
    }

    @Override
    public ResponseResult updateMa(ApiMapping a) {
        int i = apiMappingMapper.updateByPrimaryKeySelective(a);
        if (i>0) {
            return ResponseResult.getSuccess();
        }
        return ResponseResult.getFail("修改失败");
    }
}
